<template>
  <section class="ch_tree_container">
    <Treenode
      v-for="(item, i) in treeData"
      :key="i"
      ref="treeRef"
      :treenode="item"
      :inSelect="inSelect"
    ></Treenode>
  </section>
</template>

<script>
import { treeEvents } from './tree-events'
import Treenode from './tree-node'
export default {
  inheritAttrs: false,
  components: {
    Treenode
  },
  provide() {
    return this.$props
  },
  props: {
    inSelect: Boolean,
    lazy: Boolean,
    load: Function,
    valKey: String,
    showCheckbox: {
      type: Boolean
    },
    treeData: {
      type: Array,
      required: !0
    }
  },
  data() {
    return {}
  },
  methods: {
    getCheckedNodes() {
      treeEvents.initChecked()
      this.$refs.treeRef.forEach((dom) => {
        dom.getCheckedNodes()
      })
      return treeEvents.checkedList
    },
    getHalfCheckedNodes() {
      treeEvents.initHalfChecked()
      this.$refs.treeRef.forEach((dom) => {
        dom.getHalfNodes()
      })
      return treeEvents.halfCheckedList
    }
  },
  created() {
    if (this.lazy && typeof this.load !== 'function') {
      throw new Error('lazy load function is required')
    }
  },
  beforeDestroy() {
    treeEvents.resetState()
  }
}
</script>
<style lang="less">
// .ch_tree_container {
// }
</style>
